package com.changgou.web.order.controller;

import com.changgou.pay.feign.PayFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

/**
 * 支付controller
 */
@Controller
@RequestMapping("/wpay")
public class WebPayController {

    @Autowired
    private PayFeign payFeign;

    /**
     * 预支付接口
     * @return
     */
    @GetMapping("/nativePay")
    public String nativePay(Model model) throws Exception {
        //通过feign远程调用技术, 调用支付业务服务的预支付接口
        Map resultMap = payFeign.nativePay();

        //预支付链接
        model.addAttribute("code_url", resultMap.get("code_url"));
        //支付订单的订单号
        model.addAttribute("orderId", resultMap.get("orderId"));
        //总支付金额
        model.addAttribute("payMoney", Integer.parseInt(String.valueOf(resultMap.get("totalMoney"))));

        //跳转到二维码支付页面
        return "wxpay";
    }



}
